#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2021/6/9 14:47
# @Author : linjinting
# @Project : custom_protocol
# @File : unit.py
# @Software: PyCharm


def format_hex_for_str(str_):
    str_len = len(str_)
    str_ = str_.upper()
    if str_len % 2 != 0:
        str_ = str_[:-1] + '0' + str_[-1:]
    str_list = [str_[2 * i:2 * (i + 1)] for i in range(int(str_len / 2))]
    return " ".join(str_list)


def format_hex_for_bytes(bytes_):
    str_ = bytes_.hex()
    return format_hex_for_str(str_)
